import java.io.IOException;
import java.sql.SQLException;

import org.protege.owlapi.apibinding.ProtegeOWLManager;
import org.protege.owlapi.database.DatabaseSupport;
import org.protege.owlapi.model.ProtegeOWLOntologyManager;
import org.semanticweb.owlapi.io.OWLRendererException;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;

import org.coode.owlapi.owlxml.renderer.OWLXMLRenderer;


public class OntologyLoaderFromDB {
	
	public static String ONTOLOGY   = "https://owl-test.googlecode.com/svn/trunk/ontology/RoutingModel.owl";
	public static String DB_PREFIX  = "routing";
//	public static String ONTOLOGY   = "http://purl.obolibrary.org/obo/po.owl";	
//	public static String DB_PREFIX  = "po";
//	public static String ONTOLOGY   = "http://www.loa.istc.cnr.it/ontologies/DLP_397.owl";	
//	public static String DB_PREFIX  = "DLP_397";


	
	public static void main(String[] args) {
		OWLOntology ont = null;

		System.out.println("Carregando ontologia do BD usando o namespace: " + ONTOLOGY);

		ProtegeOWLOntologyManager manager = ProtegeOWLManager.createOWLOntologyManager();	
		try {
			DatabaseSupport.useDatabaseOntologyFactory(manager, 
					"jdbc:mysql://localhost/test", 
	                "johann", 
	                "");

			ont = manager.loadOntology(IRI.create(ONTOLOGY));	

		} catch (ClassNotFoundException | IOException | SQLException | OWLOntologyCreationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		OWLXMLRenderer rend = new OWLXMLRenderer(manager);
		try {
			rend.render(ont, System.out);
		} catch (OWLRendererException e) {
			e.printStackTrace();
		}

		System.out.print(ont.getClassesInSignature());
	}
	
}
